#include "MenuInsertarPersona.h"

MenuInsertarPersona::MenuInsertarPersona() {
	command = new InsertarPersonaCommand;
}

MenuInsertarPersona::~MenuInsertarPersona() {
	delete command;
}

void MenuInsertarPersona::update(){
	string input;
	if(!command->nombreSeteado()){
		cout << "Nombre:" << endl;
		cin.clear();
		getline(cin, input);
		this->command->setNombre(input);
	}
	if(!command->direccionSeteada()){
		cout << "Direccion:" << endl;
		cin.clear();
		getline(cin, input);
		this->command->setDireccion(input);
	}
	if(!command->telefonoSeteado()){
		cout << "Telefono:" << endl;
		cin.clear();
		getline(cin, input);
		this->command->setTelefono(input);
	}
	if(command->parametrosSeteados()){
		try{
			command->Execute();
			cout << "Registro insertado correctamente" << endl;
		}catch (ErrorGestorException & e) {
			cout << "Error al insertar: " << e.what() << endl;
		}catch(ValorInvalidoException & e){
			cout << "Valor invalido: " << e.what() << endl;
		}
	}
	bool preguntar = true;
	while(preguntar){
		cout << "Desea ingresar otro registro (S/N) ";
		getline(cin, input);
		if (input.c_str()[0] == 'S')
			preguntar = false;
		else if(input.c_str()[0] == 'N'){
			MenuStack::getInstance()->pop();
			preguntar = false;
		}
	}
}



